package com.gaoxk.interceptor;

import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;

public class ServerUtf8OutInterceptor extends AbstractPhaseInterceptor<Message> {
    // 在消息写入阶段（WRITE）拦截，确保编码设置在输出前生效
    public ServerUtf8OutInterceptor() {
        super(Phase.WRITE);
    }

    @Override
    public void handleMessage(Message message) throws Fault {
        // 设置 SOAP 响应的 Content-Type 为 UTF-8
        // SOAP 1.1 通常用 "text/xml;charset=UTF-8"
        // SOAP 1.2 通常用 "application/soap+xml;charset=UTF-8"
        message.put(Message.CONTENT_TYPE, "text/xml;charset=UTF-8");
    }
}